package com.gph.saviorframework.es.core.facet.request;

import com.gph.saviorframework.es.core.facet.AbstractFacetRequest;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.springframework.util.Assert;

@Deprecated
public class StatisticalFacetRequest extends AbstractFacetRequest {

	private String field;

	private String[] fields;

	public StatisticalFacetRequest(String name) {
		super(name);
	}

	public void setField(String field) {
		this.field = field;
	}

	public void setFields(String... fields) {
		throw new UnsupportedOperationException("Native Facet are not supported in Elasticsearch 2.x - use Aggregation");
	}

	public AbstractAggregationBuilder getFacet() {
		Assert.notNull(getName(), "Facet name can't be a null !!!");
		Assert.isTrue(StringUtils.isNotBlank(field) && fields == null, "Please select field or fields on which to build the facets !!!");
		return AggregationBuilders.extendedStats(getName()).field(field);
	}
}